# -*- coding: utf-8 -*-
"""简单的 tabbar 图标生成脚本"""
from PIL import Image, ImageDraw

SIZE = 81
NORMAL = (122, 126, 131)  # #7A7E83
ACTIVE = (0, 122, 255)    # #007AFF

def home(draw, color):
    """房子图标"""
    x, y = SIZE//2, SIZE//2
    # 屋顶
    draw.polygon([(x, y-20), (x-15, y-5), (x+15, y-5)], fill=color)
    # 房子主体
    draw.rectangle([x-15, y-5, x+15, y+15], fill=color, outline=color)
    # 门
    draw.rectangle([x-6, y+2, x+6, y+15], fill=(255,255,255), outline=color)

def favorite(draw, color):
    """心形图标"""
    x, y = SIZE//2, SIZE//2
    # 两个圆 + 三角形
    draw.ellipse([x-12, y-8, x-2, y+2], fill=color)
    draw.ellipse([x+2, y-8, x+12, y+2], fill=color)
    draw.polygon([(x, y+8), (x-12, y-2), (x+12, y-2)], fill=color)

def profile(draw, color):
    """用户图标"""
    x, y = SIZE//2, SIZE//2
    # 头
    draw.ellipse([x-8, y-12, x+8, y+4], fill=color)
    # 身体
    draw.polygon([(x-12, y+4), (x+12, y+4), (x+10, y+20), (x-10, y+20)], fill=color)

icons = {
    'home': home,
    'favorite': favorite,
    'profile': profile
}

def generate():
    import os
    out_dir = os.path.join(os.path.dirname(__file__), '..', 'src', 'static', 'tabbar')
    os.makedirs(out_dir, exist_ok=True)
    
    for name, draw_func in icons.items():
        # 普通状态
        img = Image.new('RGBA', (SIZE, SIZE), (255,255,255,0))
        draw_func(ImageDraw.Draw(img), NORMAL)
        img.save(os.path.join(out_dir, f'{name}.png'))
        # 激活状态
        img = Image.new('RGBA', (SIZE, SIZE), (255,255,255,0))
        draw_func(ImageDraw.Draw(img), ACTIVE)
        img.save(os.path.join(out_dir, f'{name}-active.png'))
    
    print(f'✓ 图标已生成到: {out_dir}')

if __name__ == '__main__':
    try:
        generate()
    except ImportError:
        print('请先安装 Pillow: pip install Pillow')
    except Exception as e:
        print(f'错误: {e}')

